namespace Domotica.Windows.Input
{
    using System;
    using System.ComponentModel;
    using System.Globalization;
    using System.Runtime.CompilerServices;

    public class SpeechGestureConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return (sourceType == typeof(string));
        }

        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (((((destinationType == typeof(string)) && (context != null)) && (context.Instance != null)) ? 1 : 0) != 0)
            {
                SpeechGesture instance = context.Instance as SpeechGesture;
                if (instance != null)
                {
                    return true;
                }
            }
            return false;
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object source)
        {
            if ((((source is string) && (source != null)) ? 1 : 0) == 0)
            {
                throw base.GetConvertFromException(RuntimeHelpers.GetObjectValue(source));
            }
            return new SpeechGesture((string) source);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }
            if (destinationType == typeof(string))
            {
                SpeechGesture gesture = value as SpeechGesture;
                if (gesture != null)
                {
                    return gesture.ChoiceText;
                }
            }
            throw base.GetConvertToException(RuntimeHelpers.GetObjectValue(value), destinationType);
        }
    }
}

